<?php


class EmailSenderComponent extends Object{

        var $components = array('Email');
        
        function calculaHash($nome, $email, $data){
                if(is_array($data))
                        $data = $data['year'].'-'.$data['month'].'-'.$data['day'];
                return md5($nome.$email.$data);
        }
        
        
        function smtpMessage(){
                // Constantes do SMTP
                require_once ROOT.DS.APP_DIR.DS.'config'.DS.'mail.php';
                
                $this->Email->smtpOptions = array(
                        'port'=>SMTP_PORT, 
                        'timeout'=>SMTP_TIMEOUT,
                        'host' => SMTP_HOST,
                        'username'=> SMTP_USERNAME,
                        'password'=> SMTP_PASSWORD
                );
                $this->Email->delivery = 'smtp';
                $this->Email->sendAs = 'both';
        }
        
        function setLayout($layout){
                $this->Email->layout = $layout;
        }
        
        function setTemplate($template){
                $this->Email->template = $template;
        }
        
        function from($nome = null, $email = null){
                if($email == null) $email = SMTP_USERNAME;
                if($nome == null) $nome = SMTP_USER;
                $this->Email->from = $nome.' <'.$email.'>';
        }
        
        function sendTo($nome, $email){
			$this->Email->to = $nome.' <'.$email.'>';
        }
        
        function cc($nome, $email){
        	$this->Email->cc = array("$email");
        }
        
        function bcc($email){
        	if(is_array($email)){
        		foreach($email as $item){
        			$this->Email->bcc[] = $item['Assinante']['email'];
        		}
        	}
        	else $this->Email->bcc = array("$email");
        }
        
        function assunto($assunto){
                $this->Email->subject = $assunto;
        }       

        function enviar(){
        $this->Email->send();
        }
    
        function debug(){
        echo $this->Email->smtpError;
        echo $this->Email->to;
        echo "<pre>";print_r($this);echo "</pre>";
        }
        
        
}
